#define _SHARED_FUNC
#include "protect.h"

t_protect *
add_protect (t_protect * tete, char *nom)
{
  t_protect *p;
  p = (t_protect *) malloc (sizeof (t_protect));
  p->next = tete;
  p->prev = NULL;
  if (tete)
    tete->prev = p;
  p->channel = (char *) malloc (strlen (nom) + 1);
  p->start = 0;
  p->nbuser = 0;

  strcpy (p->channel, nom);
  return p;
}

t_protect *
rm_protect (t_protect * tete, t_protect * p)
{
  t_protect *ret = tete;
  if ((!tete) || (!p))
    return tete;

  if (p->next)
    p->next->prev = p->prev;
  if (p->prev)
    p->prev->next = p->next;
  else
    ret = p->next;
  free (p->channel);
  free (p);
  return (ret);
}

t_protect *
get_protect_by_channel (t_protect * tete, char *nom)
{
  t_protect *tmp;
  for (tmp = tete; tmp; tmp = tmp->next)
      if (!strcasecmp (tmp->channel, nom))
	return tmp;
  return NULL;
}
